package com.hspedu.test;

import javax.swing.*;
import java.awt.*;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/12
 * @time 18:33
 */
public class DrawTank01 extends JFrame{
    public static void main(String[] args) {
        new DrawTank01();
    }

    private MyPanel myPanel;

    public DrawTank01(){
        if (myPanel == null)
            myPanel = new MyPanel();
        this.add(myPanel);
        this.setVisible(true);
        //设置窗口大小
        this.setSize(300,200);
        //当关闭窗口时程序退出，不这样设置的话，关闭窗口程序也不会退出
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

class MyPanel extends JPanel{
    @Override
    public void paint(Graphics g) {
        super.paint(g);

        g.setColor(Color.blue);
        g.drawRect(10,10,8,40);
        g.fillRect(10,10,8,40);

        g.drawRect(18,20,20,20);
        g.fillRect(18,20,20,20);

        g.drawRect(38,10,10,40);
        g.fillRect(38,10,10,40);

        g.setColor(Color.black);
        g.drawLine(28,5,28,30);
        g.drawLine(18,20,18,40);
        g.drawLine(38,20,38,40);
        g.drawOval(23,25,10,10);

    }
}
